package com.whcoding.test.constant;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-06-01 16:41
 **/
public enum YesOrNoEnum {

	No(0, "否"),
	Yes(1, "是");

	private Integer code;
	private String desc;

	YesOrNoEnum(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public static String getDescByCode(int code) {
		for (YesOrNoEnum item : values()) {
			if (item.getCode() == code) {
				return item.getDesc();
			}
		}
		return "";
	}

	public static YesOrNoEnum getEnumByCode(int code) {
		for (YesOrNoEnum item : values()) {
			if (item.getCode() == code) {
				return item;
			}
		}
		return null;
	}

}
